// userCenter.js
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    host: getApp().globalData.host,
    platUser:{},
    wecharUser:{},
    hidden: false,
    userMobile:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (getApp().globalData.platUser!=null){
      this.setData({
        platUser: getApp().globalData.platUser,
        wechatUser: getApp().globalData.wechatUser,
        userMobile: util.hidePrivacy(getApp().globalData.platUser.mobile),
        hidden:true
      })
    }
    wx.setNavigationBarTitle({
      title: '会员中心'
    })
  },
  onShow:function(){
    if (getApp().globalData.platUser==null){
      wx.navigateTo({
        url: '../login/login'
      });
    }else{
      this.setData({
        platUser: getApp().globalData.platUser,
        wechatUser: getApp().globalData.wechatUser,
        userMobile: util.hidePrivacy(getApp().globalData.platUser.mobile),
        hidden:true
      })
      this.confirmStatus();
    }
  },
  //非商户会员每次进入[会员中心]查询最新状态
  confirmStatus:function(){
    if(getApp().globalData.platUser==null) return;
    if(getApp().globalData.platUser.approveStatus=='Approved')
      return;
    var that = this;
    wx.request({
      url: getApp().globalData.host + 'webapp/control/currentUser',
      data: {},
      header: getApp().globalData.header,
      method: 'POST',
      success: function (res) {
        if(null!=res.data&&typeof(res.data)!='undefined')
          that.setData({
            platUser:res.data
          });
      },
      fail: function (res) {},
      complete: function (res) {}
    })
  },
  manageAddress:function(){
    wx.navigateTo({
        url: '../addresses/addresses'
      });
  },
  theFuture:function(){
    wx.showToast({
      title: '即将推出，敬请期待'
    });
  },
  upgrade:function(){
    wx.navigateTo({
      url: '../member/member',
    })
  },
  viewMember:function(){
    wx.navigateTo({
      url: '../member/member?isView=true',
    })
  },
  mySupply:function(){
    wx.navigateTo({
      url: '../mySupply/mySupply',
    })
  },
  myDemand:function () {
    wx.navigateTo({
      url: '../myDemand/myDemand',
    })
  },
  myCoupon: function () {
    wx.navigateTo({
      url: '../myCoupon/myCoupon',
    })
  },
  //拨打客服电话
  contactService:function(){
    wx.makePhoneCall({
      phoneNumber: getApp().globalData.servicePhone
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})